package org.lds.simple.disruptor.producer.sequencer;

import org.lds.simple.disruptor.SequenceBarrier;
import org.lds.simple.disruptor.sequence.Sequence;

public abstract class AbstractSequencer implements Sequencer {
    /**
     * 生产者序列号
     */
    private final Sequence sequence = new Sequence();


    private SequenceBarrier sequenceBarrier;

    @Override
    public SequenceBarrier getSequenceBarrier() {
        return this.sequenceBarrier;
    }

    @Override
    public void setSequenceBarrier(SequenceBarrier sequenceBarrier) {
        this.sequenceBarrier = sequenceBarrier;
    }

    @Override
    public Sequence getSequence() {
        return sequence;
    }

    @Override
    public void updateSequence(long sequence) {
        this.sequence.set(sequence);
    }

    @Override
    public void notifyConsumer() {
        sequenceBarrier.notifyConsumer();
    }

    @Override
    public long next() {
        return -1L;
    }

    @Override
    public long allowProduce(long currProducerSequence, long currMinConsumerSequence) {
        return sequenceBarrier.allowProduce(currProducerSequence, currMinConsumerSequence);
    }

    @Override
    public long allowProduce() {
        return sequenceBarrier.allowProduce();
    }
}
